package com.gaohe.web.controller.scp;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.scp.domain.CsGuide;
import com.gaohe.scp.service.ICsGuideService;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.common.core.page.TableDataInfo;

/**
 * 系统指南Controller
 *
 * @author liuxiangyu
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/scp/guide")
public class CsGuideController extends BaseController
{
    @Autowired
    private ICsGuideService csGuideService;

    /**
     * 查询系统指南列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:guide:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsGuide csGuide)
    {
        List<CsGuide> list = csGuideService.selectCsGuideList(csGuide);
        return getDataTable(list);
    }

    /**
     * 导出系统指南列表
     */
//    @PreAuthorize("@ss.hasPermi('scp:guide:export')")
    @Log(title = "系统指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsGuide csGuide)
    {
        List<CsGuide> list = csGuideService.selectCsGuideList(csGuide);
        ExcelUtil<CsGuide> util = new ExcelUtil<CsGuide>(CsGuide.class);
        util.exportExcel(response, list, "系统指南数据");
    }

    /**
     * 获取系统指南详细信息
     */
//    @PreAuthorize("@ss.hasPermi('scp:guide:query')")
    @GetMapping(value = "/{guideId}")
    public AjaxResult getInfo(@PathVariable("guideId") Long guideId)
    {
        return success(csGuideService.selectCsGuideByGuideId(guideId));
    }

    /**
     * 管理费
     * 新增系统指南
     */
//    @PreAuthorize("@ss.hasPermi('scp:guide:add')")
    @Log(title = "系统指南", businessType = BusinessType.INSERT)
    @PostMapping("/gld")
    public AjaxResult addContent(@RequestBody CsGuide csGuide)
    {
        String content = csGuide.getContent();
        if (content==null){
            return error("请输入内容");
        }
        csGuideService.insertCsGuide(csGuide);
        return toAjax(1);
    }

    /**
     * 管理端
     * 修改系统指南
     */
//    @PreAuthorize("@ss.hasPermi('scp:guide:edit')")
    @Log(title = "系统指南", businessType = BusinessType.UPDATE)
    @PutMapping("/gld")
    public AjaxResult GldEdit(@RequestBody CsGuide csGuide)
    {
//        String content = csGuide.getContent();
//        String s = StringUtils.substringBetween(content, "<p>", "</p>");
//        if (s.equals("<br>")  || s.isBlank()){
//            return error("请输入内容");
//        }
        System.err.println(csGuide);
        csGuideService.updateCsGuide(csGuide);
        return toAjax(1);
    }

    /**
     * 删除系统指南
     */
//    @PreAuthorize("@ss.hasPermi('scp:guide:remove')")
    @Log(title = "系统指南", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guideIds}")
    public AjaxResult remove(@PathVariable Long[] guideIds)
    {
        csGuideService.deleteCsGuideByGuideIds(guideIds);
        return toAjax(1);
    }
}
